#ifndef __ITQ_H__
#define __ITQ_H__

#ifdef LINUX
#include <stdint.h>  // for unit32_t
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct itq_msg {
    struct itq_msg      *next;
    int                 len;
    char                data[0];
} itq_msg_t;

typedef struct it_queue {
    itq_msg_t           *itq_head;
    itq_msg_t           *itq_tail;
    unsigned int        itq_empty;
    unsigned int        get_count;
    unsigned int        put_count;
    pthread_mutex_t     itq_H_lock;
    pthread_mutex_t     itq_T_lock;
    pthread_cond_t      itq_wait;
    struct it_queue     *quark_cache;
} it_queue_info_t;

typedef it_queue_info_t *itq_t;

itq_t   itq_create();
int itq_put_msg(itq_t q, void *buf, int len);
int itq_get_msg(itq_t q, void *buf, int len);
int itq_get_msg_to(itq_t q, void *buf, int len);


#define	MAX_THREAD		10
#define	MAX_SLU_MODEL	10

typedef	struct Tag_itqThreadContext{
    pthread_mutex_t     lock;
	itq_t				pQ;
/**
 * 	Insert Your Thread Context
 */
    int					mode;
    int					fvalue;
    int					useridx;
    int					numofmodels;
    int					log[MAX_SLU_MODEL];
    float				fprob[MAX_SLU_MODEL];
    char   				*nameofcrfm[MAX_SLU_MODEL];
    char   				*input;
    char   				*output;
    MaxentModel			me;
    FILE				*fplog[MAX_SLU_MODEL];
    CRFPP::Model		*md[MAX_SLU_MODEL];

}	_THREAD_CONTEXT;

typedef	struct Tag_itqThreadInfo{
	_THREAD_CONTEXT	stContext[MAX_THREAD];
}	_THREAD_INFO;

#define	MAX_THR_QUEUE_DATA_LEN	4096
typedef	struct Tag_threadQueueEvent{
	_CA_MSG		stReq;
	char		szData[MAX_THR_QUEUE_DATA_LEN];
}	_EVTINFO;


extern	_THREAD_INFO	*pstThrInfo;

itq_t	itq_thread_create(_THREAD_CONTEXT *pInfo, void*(*ThrFunc)(void*), void *pvParam, int nDetachF);
int		itq_push(itq_t q, void *msg, int len);
int		itq_pop(itq_t q, void *buf, int len);

#ifdef __cplusplus
}
#endif


#endif /* __ITQ_H__ */
